package com.hckj.medical.controller;


import com.hckj.medical.entity.Prescription;
import com.hckj.medical.service.IPrescriptionService;
import com.hckj.medical.utils.Code;
import com.hckj.medical.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hckj
 * @since 2023-11-25
 */
@RestController
@RequestMapping("/medical/prescription")
public class PrescriptionController {
    @Autowired
    private IPrescriptionService prescriptionService;

    /**
     * 根据就诊方案id查询所有的就诊记录
     * @param id
     * @return
     */
    @GetMapping("/findbypid/{id}")
    public R findbypid(@PathVariable Integer id){
        List<Map> bypreId = prescriptionService.findBypreId(id);
        if (!bypreId.isEmpty()){
            return new R(Code.GET_OK,bypreId,"查询成功");
        }else {
            return new R(Code.GET_ERRO,"查询失败");
        }
    }
    @GetMapping("/findnumber/{id}")
    public R findBydouctorid(@PathVariable Integer id){
        List<Integer> prescriptions = prescriptionService.findAllmoth(id);
        if (!prescriptions.isEmpty()){
            return new R(Code.GET_OK,prescriptions,"查询成功");
        }else {
            return new R(Code.GET_ERRO,"查询失败");
        }
    }

//    添加就诊记录和修改就诊方案已治疗的次数
    @PostMapping("/addPre")
    public R addPre(@RequestBody Prescription prescription){
        prescriptionService.insertPreandUpdateSchem(prescription);
        return new R(Code.SAVE_OK,"保存成功");
    }
}
